package com.apes.crm.callCenter.repository;

import com.apes.crm.callCenter.model.CustomComplain;
import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.scm.masterdata.party.model.PartyRole;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

/**
 * 功能： 客诉单
 * @author BieBi
 * @create 2018-7-11 11:37:08
 */
public interface CustomComplainRepository extends CustomRepository<CustomComplain, String>{

    /***
     * 功能： 查询停单单据
     * @return
     */
    @Query(" select t from CustomComplain t WHERE t.stopId is not null and t.startDate < CURRENT_DATE and t.state = 'disposing' and t.active = false ")
    List<CustomComplain> findCustomComplainRestart();


    /***
     * 功能： 查询某个客户客诉总量
     * @param vip
     * @return
     */
    @Query("select count(t) from CustomComplain t where t.deleteDate is null and t.customComplainType.description = '投诉' and t.vip = :vip")
    int countCustomComplain( @Param("vip") PartyRole vip );


    List<CustomComplain> findAllByOriginIsNullAndResponsiblePersonsIsNotNullOrComplainPersonsIsNotNull();

    @Query(value = " select A.ID as id, A.vip_id as vip_id from  crm_custom_complain A WHERE 1 = 1", nativeQuery = true)
    List<Map> queryData();
}
